<?php

// Breadcrumb generator for CodeIgniter
class Breadcrumb {

    // variables
    public $link_type = ' &gt; '; // must have spaces around it
    public $breadcrumb = array();
    public $output = '';

    // clear
    public function clear()
    {
        // clear the breadcrumb library to start again
        $props = array('breadcrumb', 'output');

        // loop through
        foreach ($props as $val)
        {
            // clear
            $this->$val = null;
        }

        // completed
        return true;
    }

    // add a "crumb"
    public function add_crumb($title, $url = false, $script = 'cms')
    {
        // pass into breadcrumb array
        $this->breadcrumb[] = array('title' => $title, 'url' => $url, 'script' => $script);

        // completed
        return true;
    }

    // change link type
    public function change_link($new_link)
    {
        // change
        $this->link_type = ' ' . $new_link . ' '; // the spaces are added for visual reasons
        // completed
        return true;
    }

    // produce output
    public function output()
    {
        // define local counter
        $counter = 0;
        $this->output .= '<ol class="breadcrumb">
                            <li><a href="' .base_url(). 'dashboard"><i class="glyphicon glyphicon-home"></i></a></li>
            ';

        // loop through breadcrumbs
        foreach ($this->breadcrumb as $key => $val)
        {
            // are we using a hyperlink?
            if ($val['url'])
            {
                // add href tag
                $this->output .= '<li>
                                    <a href="' . $val['url'] . '" class="with-ajax" data-script="' . $val['script'] . '">' . $val['title'] . '</a>
                                    <i class="icon-angle-right"></i>
                                </li>';
            } else
            {
                // don't use hyperlinks
                $this->output .= '<li class="active">' . $val['title'] . '</li>';
            }

            // increment counter
            $counter++;
        }

        $this->output .= '</li>
                    </ol>';

        // return
        return $this->output;
    }
    
}